.\"
.\" Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
.\"
.\" @APPLE_LICENSE_HEADER_START@
.\"
.\" This file contains Original Code and/or Modifications of Original Code
.\" as defined in and that are subject to the Apple Public Source License
.\" Version 2.0 (the 'License'). You may not use this file except in
.\" compliance with the License. Please obtain a copy of the License at
.\" http://www.opensource.apple.com/apsl/ and read it before using this
.\" file.
.\"
.\" The Original Code and all software distributed under the License are
.\" distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
.\" EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
.\" INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
.\" FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
.\" Please see the License for the specific language governing rights and
.\" limitations under the License.
.\"
.\" @APPLE_LICENSE_HEADER_END@
.\"
.Dd Oct 19, 2004
.Dt LISTXATTR 2
.Os "Mac OS X"
.Sh NAME
.Nm listxattr,
.Nm flistxattr
.Nd list extended attribute names
.Sh SYNOPSIS
.Fd #include <sys/xattr.h>
.Ft ssize_t
.Fn listxattr "const char *path" "char *namebuf" "size_t size" "int options"
.Ft ssize_t
.Fn flistxattr "int fd" "char *namebuf" "size_t size" "int options"
.Sh DESCRIPTION
Extended attributes extend the basic attributes associated with files and
directories in the file system.  They are stored as name:data pairs associated
with file system objects (files, directories, symlinks, etc).
.Pp
.Fn listxattr
retrieves a list of names of extended attributes associated with the given
.Fa path
in the file system.
.Pp
.Fa namebuf
is a data buffer of
.Pa size
bytes for the names of the extended attributes associated with
.Fa path .
The extended attribute names are simple NULL-terminated UTF-8 strings and
are returned in arbitrary order.  No extra padding is provided between
names in the buffer.  The list will only include names of extended
attributes to which the calling process has access.  The function returns
the size of the list of names.
.Pp
.Fa options
controls how the attribute list is generated:
.Pp
.Bl -tag -width XATTR_NOFOLLOW
.It Dv XATTR_NOFOLLOW
do not follow symbolic links.
.Fn listxattr
normally lists attributes of the target of
.Fa path
if it is a symbolic link.  With this option,
.Fn listxattr
will list attributes of the link itself.
.It Dv XATTR_NOFOLLOW_ANY
do not follow any symbolic links encountered during pathname resolution. An
error is returned if a symlink is encountered before the last component of path.
.It Dv XATTR_SHOWCOMPRESSION
.Fn listxattr
and 
.Fn flistxattr
will list HFS Plus Compression extended attribute(s) (if present) for the file referred to by
.Fa path
or
.Fa fd .
.El
.Pp
If
.Fa namebuf
is set to NULL,
the function returns the size of the list of extended attribute names.
This facility can be used to determine the size of a buffer sufficiently
large to hold the names of the attributes currently associated with
.Fa path .
.Pp
.Fn flistxattr
is identical to
.Fn listxattr ,
except that it returns the list of extended attribute names associated
with the open file referenced by file descriptor
.Fa fd .
.Sh RETURN VALUES
On success, the size of the extended attribute name list is returned.  If
no accessible extended attributes are associated with the given
.Fa path
or
.Fa fd ,
the function returns zero.  On failure, -1 is returned and the global
variable
.Va errno
is set as follows.
.Sh ERRORS
.Bl -tag -width Er
.It Bq Er ENOTSUP
The file system does not support extended attributes or has the feature
disabled.
.It Bq Er ERANGE
.Fa namebuf
(as indicated by
.Fa size )
is too small to hold the list of names.
.It Bq Er EPERM
.Fa path
or
.Fa fd
refer to a file system object that does not support extended attributes.
For example, resource forks don't support extended attributes.
.\" If only EFTYPE was a POSIX error
.It Bq Er ENOTDIR
A component of
.Fa path 's
prefix is not a directory.
.It Bq Er ENAMETOOLONG
.Fa name
exceeds
.Dv XATTR_MAXNAMELEN
UTF-8 bytes, or a component of
.Fa path
exceeds
.Dv NAME_MAX
characters, or the entire
.Fa path
exceeds
.Dv PATH_MAX
characters.
.It Bq Er EACCES
Search permission is denied for a component of
.Fa path
or permission is denied to read the list of attributes from this file.
.It Bq Er ELOOP
Too many symbolic links were encountered resolving
.Fa path .
.It Bq Er ELOOP
If XATTR_NOFOLLOW_ANY option was passed and a symbolic link was encountered in
translating the pathname.
.It Bq Er EFAULT
.Fa path
points to an invalid address.
.It Bq Er EIO
An I/O error occurred.
.It Bq Er EINVAL
.Fa options
has an unsupported bit set.
.It Bq Er EINVAL
XATTR_NOFOLLOW or XATTR_NOFOLLOW_ANY option was passed in
.Fn flistxattr .
.El
.Sh SEE ALSO
.Xr getxattr 2 ,
.Xr removexattr 2 ,
.Xr setxattr 2
.Sh HISTORY
.Fn listxattr
and
.Fn flistxattr
first appeared in Mac OS X 10.4.
